<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}" />
<style>
    #singelEditItem input {
        height: 28px;
    }

    .tablestyle .selection .select2-selection {
        padding-left: 5px;
    }

    .tablestyle .select2-selection .select2-selection__rendered {
        padding-left: 0;
    }

    .tablestyle #select2-itemExp2-container {
        padding-left: 0;
    }

    .tablestyle select {
        height: 28px;
    }

    .tablestyle .select2-container {
        width: 100%;
    }

    .tablestyle .content {
        text-align: right;
        padding-left: 0;
        padding-right: 8px;
    }
</style>
<div class="modal fade" id="singelEditItemModel" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document" style="width:1020px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">单件编辑</h4>
            </div>
            <div id="singelEditItem" class="modal-body">
                <form id="editSinForm" class="form-horizontal form-bordered form-row-strippe" data-toggle="validator"
                    method="post">
                    <table id="archiveJudTableEdit" class="tablestyle">
                        <input type="hidden" id="itemIdEdit" name="itemId">
                        <tr>
                            <td class="content">题&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名</td>
                            <td class="form-group" colspan="7">
                                <input type="text" id='itemTitleEdit' name='itemTitle' placeholder="必填项" value=''/>
                            </td>
                        </tr>
                        <tr>
                            <td class="content">文件类型</td>
                            <td class="form-group" style="width:300px;">
                                <select id="itemExp1Edit" name="itemExp1" placeholder="必填项">
                                </select>
                            </td>
                            <td class="content">全&nbsp;宗&nbsp;号</td>
                            <td class="form-group">
                                <input type="text" id='itemFianEdit' name='itemFian' value='' readonly/>
                            </td>
                            <td class="content">责&nbsp;任&nbsp;者</td>
                            <td class="form-group">
                                <input type="text" id='itemResponsEdit' name='itemRespons' placeholder="必填项" value=''/>
                            </td>
                            <td class="content">单&nbsp;元&nbsp;号</td>
                            <td class="form-group">
                                <input type="text" id='itemTemporaryEdit' name='itemTemporary' value=''/>
                            </td>
                        </tr>
                        <tr>
                            <td class="content">归档单位</td>
                            <td class="form-group">
                                <select type="text" id='itemExp2Edit' name='itemExp2' placeholder="必填项" value='' style="width: 95%"></select>
                            </td>
                            <td class="content">归档年度</td>
                            <td class="form-group">
                                <input type="text" id='itemExp3Edit' name='itemExp3' placeholder="必填项" value=''/>
                            </td>
                            <td class="content">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;级</td>
                            <td class="form-group">
                                <select id="itemSecretEdit" name="itemSecret" placeholder="必填项">
                                </select>
                                <%--<input type="text" id='itemSecretEdit' name='itemSecret' placeholder="必填项" value=''/>--%>
                            </td>
                            <td class="content">保密年限</td>
                            <td class="form-group">
                                <input type="number" id='itemExp4Edit' min="0" name='itemExp4' value='' style="width: 60%;float: left"/>
                                <%--&nbsp;<span  style="font-size: 15px;">年</span>--%>
                            </td>
                        </tr>
                        <tr>
                            <td class="content">文&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</td>
                            <td class="form-group">
                                <input type="text" id='itemNameEdit' name='itemName' placeholder="必填项" value=''/>
                            </td>
                            <td class="content">发文日期</td>
                            <td class="form-group">
                                <input type="text" id='itemCreateTimeEdit' name='itemCreateTime' placeholder="必填,yyyy/mm/dd"
                                       value=''/>
                            </td>
                            <td class="content">保管期限</td>
                            <td class="form-group">
                                <select id="itemNumEdit" name="itemNum" placeholder="必填项">
                                    <%--<option value="10年">10年</option>
                                    <option value="20年">20年</option>
                                    <option value="30年">30年</option>
                                    <option value="永久">永久</option>--%>
                                </select>
                            </td>
                            <td class="content">页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数</td>
                            <td class="form-group">
                                <input type="number" id='itemPageEdit' min="0" name='itemPageEdit' value=''/>
                            </td>
                        </tr>
                        <tr>
                            <td class="content">
                                是否公开
                            </td>
                            <td class="form-group" style="width: 300px;">
                                <select id="itemPublicStatus" name="itemPublicStatus" >
                                    <option value="0">未公开</option>
                                    <option value="1">公开</option>
                                </select>
                            </td>
                            <td class="content">
                                载体类型
                            </td>
                            <td class="form-group" style="width: 300px;">
                                <select id="itemCarrier" name="itemCarrier" >
                                    <option value="2">共存</option>
                                    <option value="1">仅电子</option>
                                    <option value="0">仅实体</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" id="editJud" onclick="EditSigAction()" class="btn btn-primary">提交变更</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        formEditValidator();

        //关闭事件
        $('#singelEditItemModel').on('hide.bs.modal', function () {
            $("#editSinForm").data('bootstrapValidator').destroy();
            $('#editSinForm').data('bootstrapValidator', null);
            formEditValidator();
            $table.bootstrapTable('refresh');
        });
    });

    function formEditValidator(){
        $("#editSinForm").bootstrapValidator({
            live: 'submitted',//验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
            excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件，比如被禁用的或者被隐藏的
            submitButtons: '#editJud',//指定提交按钮，如果验证失败则变成disabled，但我没试成功，反而加了这句话非submit按钮也会提交到action指定页面
            message: '通用的验证失败消息',//好像从来没出现过
            feedbackIcons: {//根据验证结果显示的各种图标
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                itemExp3: {
                    validators: {
                        callback: {
                            message: '只可输入1600至当前年份且不能为空',
                            callback: function (value, validator, $field) {
                                //callbackEdit(value);
                                var reg = /^\d{4}$/;
                                var now = new Date();
                                var year = now.getFullYear(); //获取当前年份
                                if( value.length!=0 &&reg.test(value) && parseInt(value) <= parseInt(year) && parseInt(1600) <= parseInt(value)){
                                    return true;
                                }else {
                                    return false;
                                }
                            }
                        }
                    }
                },
                itemExp2: {
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '文本框必须输入'
                        }
                    }
                },
                itemCreateTime: {
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '文本框必须输入'
                        },
                        regexp: {
                            regexp: /^\d{8}$/,
                            message: '请输入正确日期'
                        }
                    }
                },
                itemTitle: {
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '文本框必须输入'
                        }
                    }
                },
                itemName: {
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '文本框必须输入'
                        }
                    }
                },
                itemRespons: {
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '文本框必须输入'
                        }
                    }
                }
            }
        });
    }

    function callbackEdit(value){
        var now = new Date();
        var year = now.getFullYear(); //获取当前年份
        if(parseInt(1600)<=parseInt(value)<=parseInt(year)){
            return true;
        }else {
            return false;
        }
    }

    //加载所有案卷类型
    function findAllJudTypeEditSiN() {
        $.ajax({
            type: "POST",
            url: "${basePath}/pcwindow/findAllJudType",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.length != 0) {
                    var arcTypes = data.rows;
                    var str;
                    for (var i = 0; i < arcTypes.length; i++) {
                        var tyname = arcTypes[i].sortName;
                        var tyid = arcTypes[i].sortNum;
                        str += '<option value="' + tyid + '">' + tyname + '</option>'
                    }
                    $('#itemExp1Edit').html(str);
                }
            }
        });
    }

    //保存操作
    function EditSigAction() {
        $("#editSinForm").bootstrapValidator('validate');//提交验证
        if ($("#editSinForm").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
            var cmsSinEditItemObj = $("#editSinForm").serializeObject();
            var cmsSinItemEdit = JSON.stringify(cmsSinEditItemObj);
            $.ajax({
                type: "POST",
                url: "${basePath}/pcwindow/sin/editSubmit",
                dataType: "json",
                data: { cmsSinItemEdit: cmsSinItemEdit },
                success: function (data) {
                    if (data == "1") {
                        $("#editSinForm")[0].reset();
                        $('#singelEditItemModel').modal('hide');
                        confirmEvent('修改信息成功!');
                    } else {
                        confirmEvent('编辑失败,请刷新后重试!');
                    }
                }
            });
        }
    }

    /**
     *	加载所有保管期限
     */
    function findAllStorageTimeSinEdit() {
        $.ajax({
            type: "POST",
            url: "${pageContext.request.contextPath }/pcwindow/findAllStorageTime",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.length != 0) {
                    var arcStorageTime = data.rows;
                    var str;
                    for (var i = 0; i < arcStorageTime.length; i++) {
                        var tyname = arcStorageTime[i].description;
                        var tyid = arcStorageTime[i].code;
                        str += '<option value="' + tyid + '">' + tyname + '</option>'
                    }
                    $('#itemNumEdit').html(str);
                }
            }
        });
    }

    /**
     * 加载所有密级
     */
    function findAllsecretLevelSinEdit() {
        $.ajax({
            type: "POST",
            url: "${basePath}/pcwindow/findAllSecretLevel",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.length != 0) {
                    var findAllsecretAAALevel = data.rows;
                    var strs = '<option value="">请选择</option>';
                    for (var i = 0; i < findAllsecretAAALevel.length; i++) {
                        var nameEdit = findAllsecretAAALevel[i].description;
                        var idEdit = findAllsecretAAALevel[i].code;
                        strs += '<option value="' + idEdit + '">' + nameEdit + '</option>'
                    }
                    $('#itemSecretEdit').html(strs);
                }
            }
        });
    }
    /**
     * 加载组织机构
     */
    function initSelectarcApartmentEdit() {
        $.ajax({
            type: "POST",
            url: BASE_PATH + "/pcwindow/findAllOrg",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.length != 0) {
                    initMaterialInput();
                    $('#itemExp2Edit').select2({
                        placeholder: '请选择',
                        allowClear: true
                    });
                }
                var str = '';
                for (var i = 0; i < data.length; i++) {
                    var name = data[i].name;
                    var id = data[i].organizationId;
                    str += '<option value="' + id + '">' + name + '</option>'
                }
                $('#itemExp2Edit').html(str);
            }
        });
    }
</script>